//
//  ViewController.m
//  LCAESFileEncryption
//
//  Created by yxl on 2022/4/1.
//

#import "ViewController.h"
#import "LCArchiveManager.h"

@interface ViewController ()
@property(strong,nonatomic)UIImageView *imageView;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self createUI];
    [self imageEncryption];
    [self plistEncryption];
}

#pragma mark - 加密
// 加密image
- (void)imageEncryption{
    [LCArchiveManager imageEncryptionImageName:@"testImage" Type:@"jpg"];
}

// 加密plist文件
- (void)plistEncryption{
    [LCArchiveManager plistEncryptionPlistName:@"Info" Type:@"plist"];
}

#pragma mark - 解密
// 解密图片
- (void)imageClicked{
    self.imageView.image = [LCArchiveManager imageDecryptionImageFileName:@"testImage"];
}

// 解密plist文件
- (void)plistClicked{
    NSDictionary *dic = [LCArchiveManager plistDecryptionPlistFileName:@"Info"];
    NSLog(@"dic=====%@",dic);
}

#pragma mark - 清除加密文件
- (void)clearClicked{
    [LCArchiveManager clearArchiverData];
}

-(void)createUI
{
    CGFloat iPhoneHeight = self.view.bounds.size.height;
    CGFloat iPhoneWidth  = self.view.bounds.size.width;
    
    
    UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(50.f, 100.f, iPhoneWidth-100.f, 50.f)];
    [button addTarget:self action:@selector(plistClicked) forControlEvents:UIControlEventTouchUpInside];
    [button setTitle:@"查看PLIST" forState:UIControlStateNormal];
    button.layer.cornerRadius = 5.f;
    button.clipsToBounds = YES;
    button.layer.borderWidth = 1.f;
    button.layer.borderColor = [UIColor blackColor].CGColor;
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.view addSubview:button];
    
    UIButton *button1 = [[UIButton alloc]initWithFrame:CGRectMake(50.f, 200.f, iPhoneWidth-100.f, 50.f)];
    [button1 addTarget:self action:@selector(imageClicked) forControlEvents:UIControlEventTouchUpInside];
    [button1 setTitle:@"查看图片" forState:UIControlStateNormal];
    button1.layer.cornerRadius = 5.f;
    button1.clipsToBounds = YES;
    button1.layer.borderWidth = 1.f;
    button1.layer.borderColor = [UIColor blackColor].CGColor;
    [button1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.view addSubview:button1];
    
    UIButton *button2 = [[UIButton alloc]initWithFrame:CGRectMake(50.f, 300.f, iPhoneWidth-100.f, 50.f)];
    [button2 addTarget:self action:@selector(clearClicked) forControlEvents:UIControlEventTouchUpInside];
    [button2 setTitle:@"清除加密文件" forState:UIControlStateNormal];
    button2.layer.cornerRadius = 5.f;
    button2.clipsToBounds = YES;
    button2.layer.borderWidth = 1.f;
    button2.layer.borderColor = [UIColor blackColor].CGColor;
    [button2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.view addSubview:button2];
    
    
    self.imageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, iPhoneHeight/2, iPhoneWidth-20, 300)];
    self.imageView.layer.borderColor = [UIColor blackColor].CGColor;
    self.imageView.layer.borderWidth = 1.f;
    self.imageView.clipsToBounds  = YES;
    self.imageView.layer.cornerRadius = 5.f;
    [self.view addSubview:self.imageView];
}


@end
